home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / ex5-10.c < prev    next >
C/C++ Source or Header  |  1990-05-15  |  1KB  |  50 lines

  1. // ex5-10 -- one dimensional automatic derivatives with
  2. //           class AutoDeriv
  3.  
  4. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex5-10.c,v 3.0 90/05/15 22:45:12 kgorlen Rel $
  5.  
  6. #include <math.h>
  7. #include <iostream.h>
  8. #include "AutoDeriv.h"
  9.  
  10. const double halfPI = M_PI_2; /* M_PI_2 from math.h */
  11.  
  12. main()
  13. {
  14.     AutoDeriv W(0,1);
  15.     AutoDeriv Y_plus = W+1;
  16.     AutoDeriv Y_times= W*2;
  17.     AutoDeriv Z = 2*W*(W+2) + W + 1;
  18.     cout << "W=" << W << endl;
  19.     cout << "W+1=" << Y_plus << endl;
  20.     cout << "W*2=" << Y_times << endl;
  21.     cout << "Z = 2*W*(W+2)+W+1="<< Z << endl;
  22.     cout << "(2*(W+1)).pow(3)=" << (2*(W+1)).pow(3) << endl;
  23.     cout << "2*W*Z.pow(2)=" << 2*W*Z.pow(2) << endl;
  24.     cout << endl;
  25.  
  26.     // evaluate 2*x*(sin(x)+1) at x=0
  27.     AutoDeriv X(0,1);
  28.     AutoDeriv Y = 2*X*(Sin(X)+1);
  29.  
  30.     cout << "let  X = [F(X),dF(X)] = "
  31.          << "[" << F(X)  << "," << dF(X) << "]" 
  32.          << endl;
  33.     cout << "let  Y = 2*X*(Sin(X)+1)" << "\n"
  34.          << "then Y = [F(Y),dF(Y)] = "
  35.          << "[" << F(Y)  << "," << dF(Y) << "]" 
  36.          << endl<< endl;
  37.     
  38.     // evaluate 2*x*(sin(x)+1) at x=halfPI
  39.     AutoDeriv U(halfPI,1); 
  40.     AutoDeriv V = 2*U*(Sin(U)+1);
  41.  
  42.     cout << "let  U = [F(U),dF(U)] = "
  43.          << "[" << F(U)  << "," << dF(U) << "]" 
  44.          << endl;
  45.     cout << "let  V = 2*U*(Sin(U)+1)" << "\n"
  46.          << "then V = [F(V),dF(V)] = "
  47.          << "[" << F(V)  << "," << dF(V) << "]" 
  48.          << endl;
  49. }
  50.